Left Termination of the query pattern balance_in_2(g, a) w.r.t. the given Prolog program could successfully be proven:



Prolog
  ↳ PrologToPiTRSProof

Clauses:

balance(T, TB) :- balance(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])).
balance(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)).
balance(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) :- ','(balance(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)), balance(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))).

Queries:

balance(g,a).

We use the technique of [30]. With regard to the inferred argument filtering the predicates were used in the following modes:
balance_in: (b,f)
balance_in: (b,b,b,b,b)
Transforming Prolog into the following Term Rewriting System:
Pi-finite rewrite system:
The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_ggggg(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_ggggg(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_ggggg(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_ggggg(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_ggggg(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_ggggg(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x3)
balance_in_ggggg(x1, x2, x3, x4, x5)  =  balance_in_ggggg(x1, x2, x3, x4, x5)
-(x1, x2)  =  -
','(x1, x2)  =  ','(x2)
.(x1, x2)  =  .(x1)
nil  =  nil
balance_out_ggggg(x1, x2, x3, x4, x5)  =  balance_out_ggggg
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_ggggg(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_ggggg(x3, x18)
U3_ggggg(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_ggggg(x18)
balance_out_ga(x1, x2)  =  balance_out_ga

Infinitary Constructor Rewriting Termination of PiTRS implies Termination of Prolog



↳ Prolog
  ↳ PrologToPiTRSProof
PiTRS
      ↳ DependencyPairsProof

Pi-finite rewrite system:
The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_ggggg(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_ggggg(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_ggggg(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_ggggg(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_ggggg(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_ggggg(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x3)
balance_in_ggggg(x1, x2, x3, x4, x5)  =  balance_in_ggggg(x1, x2, x3, x4, x5)
-(x1, x2)  =  -
','(x1, x2)  =  ','(x2)
.(x1, x2)  =  .(x1)
nil  =  nil
balance_out_ggggg(x1, x2, x3, x4, x5)  =  balance_out_ggggg
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_ggggg(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_ggggg(x3, x18)
U3_ggggg(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_ggggg(x18)
balance_out_ga(x1, x2)  =  balance_out_ga


Using Dependency Pairs [1,30] we result in the following initial DP problem:
Pi DP problem:
The TRS P consists of the following rules:

BALANCE_IN_GA(T, TB) → U1_GA(T, TB, balance_in_ggggg(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
BALANCE_IN_GA(T, TB) → BALANCE_IN_GGGGG(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))
BALANCE_IN_GGGGG(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_GGGGG(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
BALANCE_IN_GGGGG(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → BALANCE_IN_GGGGG(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))
U2_GGGGG(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_GGGGG(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U2_GGGGG(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → BALANCE_IN_GGGGG(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))

The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_ggggg(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_ggggg(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_ggggg(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_ggggg(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_ggggg(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_ggggg(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x3)
balance_in_ggggg(x1, x2, x3, x4, x5)  =  balance_in_ggggg(x1, x2, x3, x4, x5)
-(x1, x2)  =  -
','(x1, x2)  =  ','(x2)
.(x1, x2)  =  .(x1)
nil  =  nil
balance_out_ggggg(x1, x2, x3, x4, x5)  =  balance_out_ggggg
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_ggggg(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_ggggg(x3, x18)
U3_ggggg(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_ggggg(x18)
balance_out_ga(x1, x2)  =  balance_out_ga
U3_GGGGG(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_GGGGG(x18)
BALANCE_IN_GA(x1, x2)  =  BALANCE_IN_GA(x1)
U2_GGGGG(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_GGGGG(x3, x18)
U1_GA(x1, x2, x3)  =  U1_GA(x3)
BALANCE_IN_GGGGG(x1, x2, x3, x4, x5)  =  BALANCE_IN_GGGGG(x1, x2, x3, x4, x5)

We have to consider all (P,R,Pi)-chains

↳ Prolog
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
PiDP
          ↳ DependencyGraphProof

Pi DP problem:
The TRS P consists of the following rules:

BALANCE_IN_GA(T, TB) → U1_GA(T, TB, balance_in_ggggg(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
BALANCE_IN_GA(T, TB) → BALANCE_IN_GGGGG(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))
BALANCE_IN_GGGGG(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_GGGGG(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
BALANCE_IN_GGGGG(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → BALANCE_IN_GGGGG(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))
U2_GGGGG(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_GGGGG(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U2_GGGGG(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → BALANCE_IN_GGGGG(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))

The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_ggggg(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_ggggg(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_ggggg(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_ggggg(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_ggggg(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_ggggg(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x3)
balance_in_ggggg(x1, x2, x3, x4, x5)  =  balance_in_ggggg(x1, x2, x3, x4, x5)
-(x1, x2)  =  -
','(x1, x2)  =  ','(x2)
.(x1, x2)  =  .(x1)
nil  =  nil
balance_out_ggggg(x1, x2, x3, x4, x5)  =  balance_out_ggggg
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_ggggg(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_ggggg(x3, x18)
U3_ggggg(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_ggggg(x18)
balance_out_ga(x1, x2)  =  balance_out_ga
U3_GGGGG(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_GGGGG(x18)
BALANCE_IN_GA(x1, x2)  =  BALANCE_IN_GA(x1)
U2_GGGGG(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_GGGGG(x3, x18)
U1_GA(x1, x2, x3)  =  U1_GA(x3)
BALANCE_IN_GGGGG(x1, x2, x3, x4, x5)  =  BALANCE_IN_GGGGG(x1, x2, x3, x4, x5)

We have to consider all (P,R,Pi)-chains
The approximation of the Dependency Graph [30] contains 1 SCC with 3 less nodes.

↳ Prolog
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
PiDP
              ↳ UsableRulesProof

Pi DP problem:
The TRS P consists of the following rules:

BALANCE_IN_GGGGG(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → BALANCE_IN_GGGGG(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))
U2_GGGGG(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → BALANCE_IN_GGGGG(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))
BALANCE_IN_GGGGG(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_GGGGG(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))

The TRS R consists of the following rules:

balance_in_ga(T, TB) → U1_ga(T, TB, balance_in_ggggg(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, [])))
balance_in_ggggg(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_ggggg(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_ggggg(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_ggggg(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))
U1_ga(T, TB, balance_out_ggggg(T, -(I, []), -(.(','(TB, -(I, [])), X), X), -(Rest, []), -(Rest, []))) → balance_out_ga(T, TB)

The argument filtering Pi contains the following mapping:
balance_in_ga(x1, x2)  =  balance_in_ga(x1)
U1_ga(x1, x2, x3)  =  U1_ga(x3)
balance_in_ggggg(x1, x2, x3, x4, x5)  =  balance_in_ggggg(x1, x2, x3, x4, x5)
-(x1, x2)  =  -
','(x1, x2)  =  ','(x2)
.(x1, x2)  =  .(x1)
nil  =  nil
balance_out_ggggg(x1, x2, x3, x4, x5)  =  balance_out_ggggg
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_ggggg(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_ggggg(x3, x18)
U3_ggggg(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_ggggg(x18)
balance_out_ga(x1, x2)  =  balance_out_ga
U2_GGGGG(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_GGGGG(x3, x18)
BALANCE_IN_GGGGG(x1, x2, x3, x4, x5)  =  BALANCE_IN_GGGGG(x1, x2, x3, x4, x5)

We have to consider all (P,R,Pi)-chains
For (infinitary) constructor rewriting [30] we can delete all non-usable rules from R.

↳ Prolog
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
            ↳ PiDP
              ↳ UsableRulesProof
PiDP
                  ↳ PiDPToQDPProof

Pi DP problem:
The TRS P consists of the following rules:

BALANCE_IN_GGGGG(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → BALANCE_IN_GGGGG(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))
U2_GGGGG(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → BALANCE_IN_GGGGG(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))
BALANCE_IN_GGGGG(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_GGGGG(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))

The TRS R consists of the following rules:

balance_in_ggggg(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T)) → balance_out_ggggg(nil, -(X, X), -(A, B), -(A, B), -(.(','(nil, -(C, C)), T), T))
balance_in_ggggg(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT)) → U2_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1)))
U2_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(L, -(IH, .(V, IT1)), -(H, T), -(HR1, TR1), -(NH, NT1))) → U3_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_in_ggggg(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT)))
U3_ggggg(L, V, R, IH, IT, LB, VB, RB, A, D, H, X, T, HR, TR, NH, NT, balance_out_ggggg(R, -(IT1, IT), -(HR1, TR1), -(HR, TR), -(NT1, NT))) → balance_out_ggggg(tree(L, V, R), -(IH, IT), -(.(','(tree(LB, VB, RB), -(A, D)), H), .(','(LB, -(A, .(VB, X))), .(','(RB, -(X, D)), T))), -(HR, TR), -(NH, NT))

The argument filtering Pi contains the following mapping:
balance_in_ggggg(x1, x2, x3, x4, x5)  =  balance_in_ggggg(x1, x2, x3, x4, x5)
-(x1, x2)  =  -
','(x1, x2)  =  ','(x2)
.(x1, x2)  =  .(x1)
nil  =  nil
balance_out_ggggg(x1, x2, x3, x4, x5)  =  balance_out_ggggg
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U2_ggggg(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_ggggg(x3, x18)
U3_ggggg(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U3_ggggg(x18)
U2_GGGGG(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)  =  U2_GGGGG(x3, x18)
BALANCE_IN_GGGGG(x1, x2, x3, x4, x5)  =  BALANCE_IN_GGGGG(x1, x2, x3, x4, x5)

We have to consider all (P,R,Pi)-chains
Transforming (infinitary) constructor rewriting Pi-DP problem [30] into ordinary QDP problem [15] by application of Pi.

↳ Prolog
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
            ↳ PiDP
              ↳ UsableRulesProof
                ↳ PiDP
                  ↳ PiDPToQDPProof
QDP
                      ↳ QDPSizeChangeProof

Q DP problem:
The TRS P consists of the following rules:

BALANCE_IN_GGGGG(tree(L, V, R), -, -, -, -) → BALANCE_IN_GGGGG(L, -, -, -, -)
BALANCE_IN_GGGGG(tree(L, V, R), -, -, -, -) → U2_GGGGG(R, balance_in_ggggg(L, -, -, -, -))
U2_GGGGG(R, balance_out_ggggg) → BALANCE_IN_GGGGG(R, -, -, -, -)

The TRS R consists of the following rules:

balance_in_ggggg(nil, -, -, -, -) → balance_out_ggggg
balance_in_ggggg(tree(L, V, R), -, -, -, -) → U2_ggggg(R, balance_in_ggggg(L, -, -, -, -))
U2_ggggg(R, balance_out_ggggg) → U3_ggggg(balance_in_ggggg(R, -, -, -, -))
U3_ggggg(balance_out_ggggg) → balance_out_ggggg

The set Q consists of the following terms:

balance_in_ggggg(x0, x1, x2, x3, x4)
U2_ggggg(x0, x1)
U3_ggggg(x0)

We have to consider all (P,Q,R)-chains.
By using the subterm criterion [20] together with the size-change analysis [32] we have proven that there are no infinite chains for this DP problem.

From the DPs we obtained the following set of size-change graphs: